<%--
  Created by IntelliJ IDEA.
  User: waqwb
  Date: 2021/12/24
  Time: 10:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="C" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
    <title>当当图书 – 全球最大的中文网上书店</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>
    <link href="${ctx}/css/book.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/css/second.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/css/secBook_Show.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/css/shopping_vehicle.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/css/public_footer.css" rel="stylesheet" type="text/css"/>
    <script type="application/javascript" src="${ctx}/js/jquery-3.5.0.min.js"></script>
</head>

<body>
<br/>
<br/>
<div class="my_shopping">
    <img class="pic_shop" src="${ctx}/images/pic_myshopping.gif"/>
</div>
<c:choose>
    <c:when test="${empty cart}">
        <div id="div_no_choice">
            <div class="choice_title"></div>
            <div class="no_select">
                您还没有选购任何商品[
                <a href='${ctx}/bookList'> 继续挑选商品&gt;&gt;</a>]
            </div>
        </div>
    </c:when>
    <c:otherwise>
        <div id="div_choice" class="choice_merch">
            <h2 id="cart_tips">
                您已选购以下商品
            </h2>
            <div class="choice_bord">
                <table class="tabl_buy" id="tbCartItemsNormal">
                    <tr class="tabl_buy_title">
                        <td class="buy_td_6">
                            <span>&nbsp;</span>
                        </td>
                        <td>
                            <span class="span_w1">商品名</span>
                        </td>
                        <td class="buy_td_5">
                            <span class="span_w2">市场价</span>
                        </td>
                        <td class="buy_td_4">
                            <span class="span_w3">当当价</span>
                        </td>
                        <td class="buy_td_1">
                            <span class="span_w2">数量</span>
                        </td>
                        <td class="buy_td_2">
                            <span>变更数量</span>
                        </td>
                        <td class="buy_td_1">
                            <span>删除</span>
                        </td>
                    </tr>
                    <tr class='objhide'>
                        <td colspan="8">
                            &nbsp;
                        </td>
                    </tr>

                    <c:forEach var="cartItem" items="${cart}">
                        <tr class='td_no_bord'>
                            <td style='display: none'>
                                    ${cartItem.value.id}
                            </td>
                            <td class="buy_td_6">
                                <span class="objhide"><img/> </span>
                            </td>
                            <td>
                                <a href="#">${cartItem.value.bookName}</a>
                            </td>
                            <td class="buy_td_5">
                                <span class="c_gray">￥${cartItem.value.fixedPrice}</span>
                            </td>
                            <td class="buy_td_4">
                                &nbsp;&nbsp;
                                <span>￥${cartItem.value.dangPrice} </span>
                            </td>
                            <td class="buy_td_1">
                                &nbsp;${cartItem.value.amount}
                            </td>

                            <td>
                                <input class="del_num" type="text" size="3"
                                       id="amount${cartItem.key }"
                                       value="${cartItem.value.amount }"/>
                                <a href="javascript:;" onclick="changeAmount(${cartItem.value.id})">变更</a>
                            </td>
                            <td>
                                <a href="#" onclick="deleteBook(${cartItem.key})">删除</a>
                            </td>
                        </tr>

                        <%--  节省的钱  --%>
                        <c:set var="sMoney"
                               value="${sMoney+cartItem.value.fixedPrice-cartItem.value.dangPrice}">
                        </c:set>
                        <%--  总共要花的钱--%>
                        <c:set var="tMoney"
                               value="${tMoney+cartItem.value.dangPrice*cartItem.value.amount}">
                        </c:set>
                    </c:forEach>
                    <!-- 购物列表结束 -->
                </table>
                <div class="choice_balance">
                    <div class="select_merch">
                        <a href='${ctx}/bookList'> 继续挑选商品&gt;&gt;</a>
                    </div>
                    <div class="total_balance">
                        <div class="save_total">
                            您共节省：
                            <span class="c_red"> ￥<span id="total_economy">${sMoney}</span></span>
                            <span style="font-size: 14px">|</span>
                            <span class="t_add">商品金额总计：</span>
                            <span class="c_red_b"> ￥<span id='total_account'>${tMoney}</span></span>
                        </div>
                        <div id="balance" class="balance">
                            <a name='checkout' href='order_info.jsp'>
                                <img src="${ctx}/images/butt_balance.gif" alt="结算" border="0" title="结算"/>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </c:otherwise>
</c:choose>
<!-- 用户删除恢复区 -->

<div id="divCartItemsRemoved" class="del_merch">

</div>
<br/>
<br/>
<br/>
<!--页尾开始 -->

<div class="public_footer">
    <div class="public_footer_bottom">
        <div class="public_footer_icp" style="line-height: 48px;">
            Copyright (C) 当当网 2004-2008, All Rights Reserved
            <a href="#" target="_blank"><img src="${ctx}/images/bottom/validate.gif" border="0" align="middle"/>
            </a>
            <a href="#" target="_blank" style="color: #666;">京ICP证041189号</a>
        </div>
    </div>
</div>
<!--页尾结束 -->
<script type="application/javascript">
    //变更书籍的数量
    function changeAmount(bookId) {
        var amount = $("#amount" + bookId).val();
        alert(amount);
        $.ajax({
            url: "${ctx}/changeAmount",
            type: "post",
            data: {"amount": amount, "bookId": bookId},
            success: function (result) {
                alert(result);
                //重新加载页面
                window.location.reload();
            }
        });
    }

    //删除图书
    function deleteBook(bookId) {
        $.ajax({
            url: "${ctx}/deleteBook",
            type: "post",
            data: {"bookId": bookId},
            success: function (result) {
                alert(result);
                //重新加载页面
                window.location.reload();
            }
        });
    }
</script>
</body>

</html>
